/**********************************************************
 * File description:TargetService.h
 * Function:靶基因管理类
 * Current Version: 1.0.0
 * Author: 夏新宇
 * Date: 2022-10-06
 *  -----
 *  Copyright by BoKun Software.
 **********************************************************/

#include "TargetService.h"

/*!
 * \brief 构造函数
 *
 *
 * \return
 *
 * Detail here!!!
 */
TargetService::TargetService()
{
    path = QCoreApplication::applicationDirPath();
    sqlD = new SqliteDriver();
    sqlD->setDBDir(path);
    sqlD->openDB(DBNAME);
}


/*!
 * \brief 析构函数
 *
 *
 *
 * \return
 *
 * Detail here!!!
 */
TargetService::~TargetService(){
    sqlD->closeDB();
}

/*!
 * \brief 新增靶基因
 *
 * \param Target target Target类型的结构体，包括新增靶基因所需数据(不包括id,create_time,update_time)
 *
 *
 * \return
 *
 * Detail here!!!
 */
void TargetService::create(Target target){
    sqlD->addData(TARGET_TABLE,target.structToQHash());
}


/*!
 * \brief 更新靶基因数据
 *
 * \param Target target Target类型的结构体，包括修改靶基因所需数据(包括id)
 *
 *
 * \return
 *
 * Detail here!!!
 */
void TargetService::update(Target target){
    sqlD->updateData(TARGET_TABLE,target.structToAllQHash(),"WHERE id = " + target.id);
}


/*!
 * \brief 删除靶基因
 *
 * \param int targetId 靶基因id
 *
 *
 * \return
 *
 * Detail here!!!
 */
void TargetService::remove(int targetId){
    sqlD->delData(TARGET_TABLE,"WHERE id = " + QString::number(targetId));
}


/*!
 * \brief 获取靶基因数据表中的全部数据
 *
 *
 *
 * \return QList类型的数据
 *
 * Detail here!!!
 */
QList<QHash<QString,QString>> TargetService::show(){
    QList<QHash<QString,QString>> res;
    sqlD->getData(TARGET_TABLE,res);
    return res;
}
